package com.example.studykt.util

import android.os.Handler
import android.os.Message
import android.widget.Toast
import com.example.studykt.MyApplication
import com.example.studykt.ui.MainActivity
import java.lang.ref.WeakReference

/**
 * on 2020/5/18
 */
class thirdhandle(mainActivity: MainActivity) : Handler() {
    private val mainActivity: WeakReference<MainActivity>

    init {
        this.mainActivity =
            WeakReference(mainActivity)
    }

    override fun handleMessage(msg: Message) {
        super.handleMessage(msg)
        val activity = mainActivity.get()
        if (activity == null || activity.isFinishing) {
            return
        }
        when (msg.what) {
            1 -> {
                Toast.makeText(MyApplication.instance,"避免内存泄漏",Toast.LENGTH_LONG).show()
            }
        }
    }
}